package com.larry.java2;

/**
 * @author larry
 * @Title: jvm_dc
 * @Package com.larry.java2
 * @Description: TODO
 * @date 7/29/2110:19 PM
 */
public class ClassLoaderTest {

    public static void main(String[] args) {
        //获取系统类加载器
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        System.out.println(systemClassLoader);

        //获取扩展类加载器
        ClassLoader parent = systemClassLoader.getParent();
        System.out.println(parent);

        //视图获取引导类加载器
        ClassLoader parent1 = parent.getParent();
        System.out.println(parent1);


        try {
            ClassLoader classLoader = Class.forName("java.lang.String").getClassLoader();
            System.out.println(classLoader);

            //自定义的类默认使用系统类加载器
            ClassLoader classLoader1 = Class.forName("com.larry.java2.ClassLoaderTest").getClassLoader();
            System.out.println(classLoader1);

            //关于数组类型的加载,使用的类的加载器与数组元素的类的加载器相同
            String[] str = new String[10];
            System.out.println(str.getClass().getClassLoader());

            ClassLoaderTest[] classLoaderTests = new ClassLoaderTest[10];
            System.out.println(classLoaderTests.getClass().getClassLoader());

            int[] ints = new int[10];
            System.out.println(ints.getClass().getClassLoader());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
